requireJS(['constant', 'site', 'handlebars', 'public'], function (Constant, site, Handlebars, Public) {
    var url = {
        selectAdminSalesman: "manager/selectAdminSalesman.do",
        insertPersonalPotantial: "manager/insertPersonalPotantial.do",
        selectPersonalPotantial: "manager/selectCleared.do",
        updatePersonalPotantial: "manager/updatePersonalsettle.do",
        ajaxqueryRegion: "manager/ajaxqueryRegion.do",
        selectSource: "manager/selectSource.do",
        insertSource: "manager/insertSource.do",
        deletetSource: "manager/deletetSource.do",
        selectLebl: "manager/selectLebl.do",
        insertLebl: "manager/insertLebl.do",
        deletetLebl: "manager/deletetLebl.do",
        selectPersonalStage:"manager/selectPersonalStage.do",
        selectOrderPageListByPid: "manager/selectOrderPageListByPid.do",
    }

    function init(){

        $(".datepicker").datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
            pickerPosition: 'bottom',
        })

        var content = JSON.parse(localStorage.getItem('content'));

        site.send({
            url: url.selectAdminSalesman,
            data: {
                pageNum: 1,
                admin_id: content.admin.id
            },
            callback: function (data) {
                var list = JSON.parse(data);
                var source2 = $("#salesMan_list_tpl").html();
                var template2 = Handlebars.compile(source2);
                var html2 = template2(list.content);
                $('#salesMan_list').html(html2);
            }
        })


        site.send({
            url: url.selectSource,
            callback: function (data) {
                var list = JSON.parse(data);
                var source = $("#source_list_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list);
                $('#source_list').html(html);
            }
        })


        site.send({
            url: url.selectPersonalStage,
            // async:false,
            callback: function (data) {
                var list = JSON.parse(data);
                var source = $("#stage_list_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list);
                $('#stage_list').html(html);
            }
        })

    }

    init();

    //新建对象，存入潜在客户列表数据
    var products = {};

    //一些全局的变量
    var source_id;
    var id;
    var personalId;
    var borrId;
    var tag_id;
    var adminId;
    var stage_id;
    var tagPageNum = 1;
    var sourcePageNum = 1;
    var selectAdminData = {
        pageNum: 1
    }

    var udpateAdmin = {};

    var pageNum = 1;

    function queryList() {
        var frontData = {
            pageNum: pageNum
        }

        if ($("#beginTime").val()) {
            frontData.create_time = $("#beginTime").val();
        }

        if ($("#endTime").val()) {
            frontData.end_time = $("#endTime").val();
        }

        if ($("#keyword").val()) {
            frontData.searchKey = $("#keyword").val();
        }

        if ($("#stage_list").val()) {
            frontData.stage_id = $("#stage_list").val();
        }
        if ($("#source_list").val()) {
            frontData.source_id = $("#source_list").val();
        }

        if ($("#salesMan_list").val()) {
            frontData.admin_id = $("#salesMan_list").val();
        }

        if ($("#isFollow").val()) {
            frontData.isfollow = $("#isFollow").val();
        }

        site.send({
            url: url.selectPersonalPotantial,
            //async:false
            data: frontData,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    var source = $("#personalPublicList_tpl").html();
                    var template = Handlebars.compile(source);

                    var menuIndex = getAurlparam('h') || 0;
                    var thirdMenusIndex = getAurlparam('t') || 0;
                    var leftIndex = getAurlparam('i') || 0;

                    var storageContent = JSON.parse(localStorage.getItem('content'));

                    var obj = {
                        content: list,
                        fourthMenus: storageContent.menus[menuIndex].children[leftIndex].children[thirdMenusIndex].children || {}
                    }

                    var html = template(obj);

                    for (var i = 0; i < list.content.list.length; i++) {
                        var v = list.content.list[i];
                        products[v.borrId] = v;
                    }

                    $('#personalPublicList').html(html);

                    var source = $("#special_fourth_tpl").html()
                    var template = Handlebars.compile(source)
                    var html = template(storageContent.menus[menuIndex].children[leftIndex].children[thirdMenusIndex].children)
                    $(".addPotentialPerson").remove();
                    $('.public-botPage-left').append(html)


                    $('.focus').on('click', function () {
                        var _this = this;
                        site.send({
                            url: url.updatePersonalPotantial,
                            data: {
                                ids: $(_this).data('id'),
                                isfollow: $(_this).data('isfollow') === 0 ? 1 : 0
                            },
                            callback: function (data) {
                                data = JSON.parse(data);
                                if (data.type === 1) {
                                    if ($(_this).hasClass('icon-aixin1')) {
                                        $(_this).removeClass('icon-aixin1').addClass('icon-aixin').data('isfollow',1);
                                    } else {
                                        $(_this).removeClass('icon-aixin').addClass('icon-aixin1').data('isfollow',0);
                                    }
                                } else {
                                    Constant.fn.Message("F", data.msg);
                                }
                            }
                        })
                    })


                    //拿到所有的复选框，当有复选框没选上的时候,取消全选
                    $("input:checkbox[name='ch_id']").on('click', function () {
                        var checkboxs = $("input:checkbox[name='ch_id']");
                        var sum = 0;
                        var length = checkboxs.length;
                        $.each(checkboxs, function (i, checkbox) {
                            if ($(checkbox).prop("checked")) {
                                sum++;
                            }
                        })
                        if (sum == length) {
                            $('#checkAllOrNot').prop("checked", true);
                        } else {
                            $('#checkAllOrNot').prop("checked", false);
                        }
                    })




                    //操作
                    $('.operations').on("change", function () {
                        id = $(this).data('id');
                        personalId = $(this).data('personalid');
                        borrId = $(this).data('borrid');
                        source_id = $(this).data('source_id');
                        tag_id = $(this).data('tag_id');
                        adminId = $(this).data('admin_id');
                        stage_id = $(this).data('stage_id');
                        if ($(this).val() === 'editPerson') {
                            var v = products[borrId];
                            //$("#edit_name").val(v.)
                            $("#edit_name").val(v.real_name);
                            $("#edit_sex option[value=" + v.sex + "]").prop('selected', true);
                            $("#edit_phone").val(v.cellphone);
                            $("#edit_vocation").val(v.vocation);
                            $("#edit_deal_rate").val(v.deal_rate);
                            $("#edit_idCard").val(v.Id_card);
                            $("#edit_address").val(v.address);

                            site.send({
                                url: url.ajaxqueryRegion,
                                // async:false,
                                data: {parentId: 0},
                                callback: function (data) {
                                    var list = JSON.parse(data);
                                    var source = $("#edit_province_list_tpl").html();
                                    var template = Handlebars.compile(source);
                                    var html = template(list);
                                    $('#edit_province_list').html(html);
                                    $("#edit_province_list").val(v.addr_province);
                                }
                            })

                            site.send({
                                url: url.ajaxqueryRegion,
                                // async:false,
                                data: {parentId: v.addr_province},
                                callback: function (data) {
                                    var list = JSON.parse(data);
                                    var source = $("#edit_city_list_tpl").html();
                                    var template = Handlebars.compile(source);
                                    var html = template(list);
                                    $('#edit_city_list').html(html);
                                    $("#edit_city_list").val(v.addr_city);
                                }
                            })

                            site.send({
                                url: url.ajaxqueryRegion,
                                // async:false,
                                data: {parentId: v.addr_city},
                                callback: function (data) {
                                    var list = JSON.parse(data);
                                    var source = $("#edit_area_list_tpl").html();
                                    var template = Handlebars.compile(source);
                                    var html = template(list);
                                    $('#edit_area_list').html(html);
                                    $("#edit_area_list").val(v.addr_area);
                                }
                            })

                            $(".editCustomer_winBox").toggle();
                        }

                        if($(this).val() === 'editSettlePerson'){
                            var v = products[borrId];
                            //$("#edit_name").val(v.)
                            $("#edit_name").val(v.real_name);
                            $("#edit_sex option[value=" + v.sex + "]").prop('selected', true);
                            $("#edit_phone").val(v.cellphone);
                            $("#edit_vocation").val(v.vocation);
                            $("#edit_deal_rate").val(v.deal_rate);
                            $("#edit_idCard").val(v.Id_card);
                            $("#edit_address").val(v.address);

                            site.send({
                                url: url.ajaxqueryRegion,
                                // async:false,
                                data: {parentId: 0},
                                callback: function (data) {
                                    var list = JSON.parse(data);
                                    var source = $("#edit_province_list_tpl").html();
                                    var template = Handlebars.compile(source);
                                    var html = template(list);
                                    $('#edit_province_list').html(html);
                                    $("#edit_province_list").val(v.addr_province);
                                }
                            })

                            site.send({
                                url: url.ajaxqueryRegion,
                                // async:false,
                                data: {parentId: v.addr_province},
                                callback: function (data) {
                                    var list = JSON.parse(data);
                                    var source = $("#edit_city_list_tpl").html();
                                    var template = Handlebars.compile(source);
                                    var html = template(list);
                                    $('#edit_city_list').html(html);
                                    $("#edit_city_list").val(v.addr_city);
                                }
                            })

                            site.send({
                                url: url.ajaxqueryRegion,
                                // async:false,
                                data: {parentId: v.addr_city},
                                callback: function (data) {
                                    var list = JSON.parse(data);
                                    var source = $("#edit_area_list_tpl").html();
                                    var template = Handlebars.compile(source);
                                    var html = template(list);
                                    $('#edit_area_list').html(html);
                                    $("#edit_area_list").val(v.addr_area);
                                }
                            })

                            $("#edit_idCard").attr('disabled',true);
                            $("#edit_name").attr('disabled',true);
                            $("#edit_phone").attr('disabled',true);
                            $(".editCustomer_winBox").toggle();
                        }

                        if ($(this).val() === 'setSource') {
                            sourcePageNum = 1;
                            $(".sourceKeyword").val('');
                            querySource();
                        }
                        if ($(this).val() === 'setLabel') {
                            tagPageNum = 1;
                            $(".tagKeyword").val('');
                            queryTag();
                        }

                        if ($(this).val() === 'setStage') {
                            queryStage();
                        }




                        // 更换业务员
                        if ($(this).val() === 'changeSalesMan') {
                            selectAdminData.admin_id = JSON.parse(localStorage.getItem('content')).admin.id;
                            udpateAdmin.pid = id;
                            changeAdminFun(adminId);
                        }

                        //查看关联订单
                        if ($(this).val() == 'checkReOrder') {
                            selectOrderData = {
                                personalId: $(this).data('personalid'),
                                pageNum: 1
                            }
                            //selectOrderData.personalId = $(this).data('personalid');
                            selectContactOrder();
                            $(".tabHint").val('-1')
                        }

                        //转化为客户
                        if ($(this).val() == 'transToRealPerson') {
                            var v = products[borrId];
                            //$("#edit_name").val(v.)
                            $("#trans_name").val(v.real_name);
                            $("#trans_sex option[value=" + v.sex + "]").prop('selected', true);
                            $("#trans_phone").val(v.cellphone);
                            $("#trans_salesMan").val(v.admin_name);
                            $(".transCustomer_winBox").show();
                        }

                        $(this).val('-1');
                    })

                    //新建客户的按钮
                    $(".addPotentialPerson").on('click', function () {
                        $(".addCustomer_winBox").toggle();

                        site.send({
                            url: url.ajaxqueryRegion,
                            // async:false,
                            data: {parentId: 0},
                            callback: function (data) {
                                var list = JSON.parse(data);
                                var source = $("#new_province_list_tpl").html();
                                var template = Handlebars.compile(source);
                                var html = template(list);
                                $('#new_province_list').html(html);
                            }
                        })

                        $("#new_province_list").on('change', function () {
                            var _this = this;
                            if ($(_this).val()) {
                                site.send({
                                    url: url.ajaxqueryRegion,
                                    // async:false,
                                    data: {parentId: $(_this).val()},
                                    callback: function (data) {
                                        var list = JSON.parse(data);
                                        var source = $("#new_city_list_tpl").html();
                                        var template = Handlebars.compile(source);
                                        var html = template(list);
                                        $('#new_city_list').html(html);
                                    }
                                })
                            } else {
                                $("#new_city_list").html('<option value="" class="" selected="selected">选择市</option>');
                                $("#new_area_list").html('<option value="" class="" selected="selected">选择区县</option>');
                            }
                        })

                        $("#new_city_list").on('change', function () {
                            var _this = this;
                            if ($(_this).val()) {
                                site.send({
                                    url: url.ajaxqueryRegion,
                                    // async:false,
                                    data: {parentId: $(_this).val()},
                                    callback: function (data) {
                                        var list = JSON.parse(data);
                                        var source = $("#new_area_list_tpl").html();
                                        var template = Handlebars.compile(source);
                                        var html = template(list);
                                        $('#new_area_list').html(html);
                                    }
                                })
                            } else {
                                $("#new_area_list").html('<option value="" class="" selected="selected">选择区县</option>');
                            }
                        })


                    })

                    if (list.content) {
                        $('.result').html(list.content.total ? list.content.total : '0');
                    }

                    $('.all-page-container').createPager({
                        current: pageNum,
                        total: list.content.total,
                        pageSize: list.content.pageSize,
                        needInput: false,
                        backFn: function (current) {
                            pageNum = current;
                            //_this.queryList(type);
                            queryList();
                        }
                    })


                    Public.record('t_personal_potential');
                    //onBindFun();
                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    }

    //查询列表
    queryList();

    //确认添加用户的按钮
    $("#sureAddCustomer").on('click', function () {
        if (!$("#new_name").val()) {
            Constant.fn.Message("I", "请输入姓名");
            return;
        }

        if (!$("#new_sex").val()) {
            Constant.fn.Message("I", "请选择性别");
            return;
        }

        if (!$("#new_phone").val()) {
            Constant.fn.Message("I", "请输入电话号码");
            return;
        }

        if (!$("#new_province_list").val()) {
            Constant.fn.Message("I", "请选择省份");
            return;
        }

        if (!$("#new_city_list").val()) {
            Constant.fn.Message("I", "请选择市");
            return;
        }

        if (!$("#new_area_list").val()) {
            Constant.fn.Message("I", "请选择区县");
            return;
        }

        if (!$("#new_address").val()) {
            Constant.fn.Message("I", "请填写详细地址");
            return;
        }

        if (!$("#new_idCard").val()) {
            Constant.fn.Message("I", "请填写身份证号");
            return;
        }

        if (!$("#new_vocation").val()) {
            Constant.fn.Message("I", "请填写行业");
            return;
        }

        if (!$("#new_deal_rate").val()) {
            Constant.fn.Message("I", "请填写成交率");
            return;
        }

        var data = {
            real_name: $("#new_name").val(),
            cellphone: $("#new_phone").val(),
            sex: $("#new_sex").val(),
            deal_rate: $("#new_deal_rate").val(),
            vocation: $("#new_vocation").val(),
            addr_province: $("#new_province_list").val(),
            addr_city: $("#new_city_list").val(),
            addr_area: $("#new_area_list").val(),
            address: $("#new_address").val(),
            Id_card: $("#new_idCard").val(),
        }

        site.send({
            url: url.insertPersonalPotantial,
            //async:false
            data: data,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    Constant.fn.Message("T", list.msg);
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })

    //修改客户弹窗的省市区
    $("#edit_province_list").on('change', function () {
        var _this = this;
        if ($(_this).val()) {
            site.send({
                url: url.ajaxqueryRegion,
                // async:false,
                data: {parentId: $(_this).val()},
                callback: function (data) {
                    var list = JSON.parse(data);
                    var source = $("#edit_city_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(list);
                    $('#edit_city_list').html(html);
                }
            })
        } else {
            $("#edit_city_list").html('<option value="" class="" selected="selected">选择市</option>');
            $("#edit_area_list").html('<option value="" class="" selected="selected">选择区县</option>');
        }
    })

    $("#edit_city_list").on('change', function () {
        var _this = this;
        if ($(_this).val()) {
            site.send({
                url: url.ajaxqueryRegion,
                // async:false,
                data: {parentId: $(_this).val()},
                callback: function (data) {
                    var list = JSON.parse(data);
                    var source = $("#edit_area_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(list);
                    $('#edit_area_list').html(html);
                }
            })
        } else {
            $("#edit_area_list").html('<option value="" class="" selected="selected">选择区县</option>');
        }
    })


    //确认修改用户按钮
    $("#sureEditCustomer").on('click', function () {
        if (!$("#edit_name").val()) {
            Constant.fn.Message("I", "请输入姓名");
            return;
        }

        if (!$("#edit_sex").val()) {
            Constant.fn.Message("I", "请选择性别");
            return;
        }

        if (!$("#edit_phone").val()) {
            Constant.fn.Message("I", "请输入电话号码");
            return;
        }

        if (!$("#edit_province_list").val()) {
            Constant.fn.Message("I", "请选择省份");
            return;
        }

        if (!$("#edit_city_list").val()) {
            Constant.fn.Message("I", "请选择市");
            return;
        }

        if (!$("#edit_area_list").val()) {
            Constant.fn.Message("I", "请选择区县");
            return;
        }

        if (!$("#edit_address").val()) {
            Constant.fn.Message("I", "请填写详细地址");
            return;
        }

        if (!$("#edit_idCard").val()) {
            Constant.fn.Message("I", "请填写身份证号");
            return;
        }

        if (!$("#edit_vocation").val()) {
            Constant.fn.Message("I", "请填写行业");
            return;
        }

        if (!$("#edit_deal_rate").val()) {
            Constant.fn.Message("I", "请填写成交率");
            return;
        }
        var data = {
            ids: id,
            real_name: $("#edit_name").val(),
            cellphone: $("#edit_phone").val(),
            sex: $("#edit_sex").val(),
            deal_rate: $("#edit_deal_rate").val(),
            vocation: $("#edit_vocation").val(),
            addr_province: $("#edit_province_list").val(),
            addr_city: $("#edit_city_list").val(),
            addr_area: $("#edit_area_list").val(),
            address: $("#edit_address").val(),
            Id_card: $("#edit_idCard").val(),
        }


        site.send({
            url: url.updatePersonalPotantial,
            //async:false
            data: data,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    Constant.fn.Message("T", list.msg);
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })


    //新增来源
    $("#addSource").on('click', function () {
        $(".addSource_winBox").toggle();
        $(".setSource_winBox").toggle();
    })

    //新增来源弹框的确定按钮
    $('.addSourceCommit').on('click', function () {
        if (!$("#sourceName").val()) {
            Constant.fn.Message("I", "请输入来源");
            return;
        }
        site.send({
            url: url.insertSource,
            data: {
                source_name: $("#sourceName").val()
            },
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type === 1) {
                    Constant.fn.Message("T", list.msg);

                    $('.addSource_winBox').toggle();

                    querySource();

                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })



    //新增标签
    $("#addTag").on('click', function () {
        $(".addTag_winBox").toggle();
        $(".setTag_winBox").toggle();
    })

    //新增来源弹框的确定按钮
    $('.addTagCommit').on('click', function () {
        if (!$("#tagName").val()) {
            Constant.fn.Message("I", "请输入标签");
            return;
        }
        site.send({
            url: url.insertLebl,
            data: {
                label_name: $("#tagName").val()
            },
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type === 1) {
                    Constant.fn.Message("T", list.msg);

                    $('.addTag_winBox').toggle();

                    queryTag();

                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })



    //点击设置来源后搜索来源列表并弹窗
    function querySource() {
        var data = {
            pageNum: sourcePageNum
        }

        if($(".sourceKeyword").val()){
            data.source_name = $(".sourceKeyword").val();
        }

        site.send({
            url: url.selectSource,
            // async:false,
            data: data,
            callback: function (data) {
                var list = JSON.parse(data);
                var source = $("#setSource_list_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list);
                $('#setSource_list').html(html);


                $('#source-page-container').createPager({
                    current: sourcePageNum,
                    total: list.content.total,
                    pageSize: list.content.pageSize,
                    needInput: false,
                    backFn: function (current) {
                        sourcePageNum = current;
                        //_this.queryList(type);
                        querySource();
                    }
                })

                if (source_id) {
                    $("input[name='source_id'][value=" + source_id + "]").prop('checked', true);
                }

                $('.deteleSource').on('click', function () {
                    var _this = this;
                    site.send({
                        url: url.deletetSource,
                        // async:false,
                        data: {
                            id: $(_this).data('id')
                        },
                        callback: function (data) {
                            var list = JSON.parse(data);
                            if (list.type === 1) {
                                Constant.fn.Message("T", list.msg);
                                $(_this).parents('tr').remove();
                            } else {
                                Constant.fn.Message("F", list.msg);
                            }
                        }
                    })
                })
            }
        })
        $(".setSource_winBox").show();
    }

    //点击设置标签后搜索标签列表并弹窗
    function queryTag() {
        var data = {
            pageNum: tagPageNum
        }
        if($(".tagKeyword").val()){
            data.label_name = $(".tagKeyword").val();
        }
        site.send({
            url: url.selectLebl,
            data: data,
            callback: function (data) {
                var list = JSON.parse(data);
                var source = $("#setTag_list_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list);
                $('#setTag_list').html(html);

                $('#tag-page-container').createPager({
                    current: tagPageNum,
                    total: list.content.total,
                    pageSize: list.content.pageSize,
                    needInput: false,
                    backFn: function (current) {
                        tagPageNum = current;
                        //_this.queryList(type);
                        queryTag();
                    }
                })


                if (tag_id) {
                    $("input[name='tag_id'][value=" + tag_id + "]").prop('checked', true);
                }

                $('.deleteTag').on('click', function () {
                    var _this = this;
                    site.send({
                        url: url.deletetLebl,
                        // async:false,
                        data: {
                            id: $(_this).data('id')
                        },
                        callback: function (data) {
                            var list = JSON.parse(data);
                            if (list.type === 1) {
                                Constant.fn.Message("T", list.msg);
                                $(_this).parents('tr').remove();
                            } else {
                                Constant.fn.Message("F", list.msg);
                            }
                        }
                    })
                })
            }
        })
        $(".setTag_winBox").show();
    }

    //点击设置阶段后搜索标签列表并弹窗
    function queryStage() {
        site.send({
            url: url.selectPersonalStage,
            // async:false,
            callback: function (data) {
                var list = JSON.parse(data);
                var source = $("#setStage_list_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list);
                $('#setStage_list').html(html);

                if (stage_id) {
                    $("#setStage_list").val(stage_id);
                }
            }
        })
        $(".setStage_winBox").toggle();
    }


    //确认设置来源
    $("#sureSetSource").on('click', function () {
        site.send({
            url: url.updatePersonalPotantial,
            // async:false,
            data: {
                ids: id,
                source_id: $("input[name='source_id']:checked").val()
            },
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type === 1) {
                    Constant.fn.Message("T", list.msg);
                    $(".setSource_winBox").toggle();
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })

    //确认设置标签
    $("#sureSetTag").on('click', function () {
        site.send({
            url: url.updatePersonalPotantial,
            // async:false,
            data: {
                ids: id,
                label_admin_id: $("input[name='tag_id']:checked").val()
            },
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type === 1) {
                    Constant.fn.Message("T", list.msg);
                    $(".setTag_winBox").toggle();
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })

    // 更换业务员
    function changeAdminFun(admin_id) {

        site.send({
            // async: false,
            url: url.selectAdminSalesman,
            data: selectAdminData,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    if (!list.content) {
                        $('.noPeople').show();
                    }
                    var obj = {
                        admin_id: admin_id,
                        list: list
                    }
                    $(".replacement").css("display", "block")
                    var list = JSON.parse(data)
                    var template = Handlebars.compile($("#admin_content_tpl").html())
                    var html = template(obj)
                    $("#admin_content").html(html)
                    $("#admin_content select option[value='" + adminId + "']").attr("selected", "selected");
                } else {
                    Constant.fn.Message('F', list.msg);
                }


            }, callError: function () {

            }
        })

        $("#changeCommitBtn").on('click', function () {
            if ($("#admin_content div select").val() != '') {
                udpateAdmin.admin_id = $("#admin_content div select").val();
            }
            site.send({
                url: url.updatePersonalPotantial,
                // async: false,
                data: {
                    ids:id,
                    admin_id:$("#admin_content div select").val()
                },
                callback: function (data) {
                    var list = JSON.parse(data)
                    if (list.type == '1') {
                        $(".replacement").css("display", "none")
                        Constant.fn.Message('T', list.msg);
                        pjaxReload();
                    } else {
                        Constant.fn.Message('F', list.msg);
                    }
                }
            })
        })
    }


    // 查看关联订单
    function selectContactOrder() {
        site.send({
            url: url.selectOrderPageListByPid,
            // async: false,
            data: selectOrderData,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    $(".associatedOrder").css("display", "block")
                    var list = JSON.parse(data)
                    var template = Handlebars.compile($("#dataList_content_tpl").html())
                    var html = template(list)
                    $("#dataList_content").html(html)

                    $("#dataList_content .orderList").on('click',function(){
                        pjaxGo("loanBefore/orderDetail.html?order_id=" + $(this).data('order_id')+ "&product_id=" + $(this).data('product_id') + "&task_id=" + $(this).data('taskId') + "&node_id=" + $(this).data('node_id') + "&s_id=" + $(this).data('s_id'));
                    })


                } else {
                    Constant.fn.Message('F', list.msg);
                }


            }
        })

    }


    $("#sureSetStage").on('click',function(){
        site.send({
            url: url.updatePersonalPotantial,
            // async:false,
            data: {
                ids: id,
                stage_id: $("#setStage_list").val()
            },
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type === 1) {
                    Constant.fn.Message("T", list.msg);
                    $(".setStage_winBox").toggle();
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", list.msg);
                }
            }
        })
    })

    $(".serach_btn").on('click',function(){
        queryList();
    })

    //确认转换按钮
    $("#sureTrans").on('click',function(){
        //queryList();
        pjaxGo("loanBefore/product_orderIn.html?pid="+ borrId + "&type=2");
    })

    $(".sourceSearch").on('click', function () {
        sourcePageNum = 1;
        querySource();
    })

    $(".tagSearch").on('click', function () {
        tagPageNum = 1;
        queryTag();
    })

    // 全选和全不选
    $("#checkAllOrNot").on('click', function () {
        $("input[name='ch_id']").prop("checked", $(this).prop("checked"))
    })

    //批量操作
    $(".supportc").on('change', function () {
        delId = "";
        var selected = $(this).find("option:selected");
        $(this).find("option:first").prop("selected", false).prop("selected", true);
        $("input[name='ch_id']:checked").each(function (index, item) {
            delId = delId + $(item).val() + ","
        })
        delId = delId.substring(0, delId.length - 1)
        if (selected.val() == '删除') {
            //删除产品
            if (!delId) {
                Constant.fn.Message('I', "未选择要删除的出借人")
                return false;
            }
        }
        $('.delete_winBox').toggle();
    })

})
